// package com.emokili.ewa.app.controller;
//
// import com.amazonaws.auth.AWSCredentials;
// import com.amazonaws.auth.AWSStaticCredentialsProvider;
// import com.amazonaws.auth.BasicAWSCredentials;
// import com.amazonaws.regions.Regions;
// import com.amazonaws.services.s3.AmazonS3;
// import com.amazonaws.services.s3.AmazonS3ClientBuilder;
// import com.amazonaws.services.s3.model.*;
// import org.apache.commons.codec.binary.Base64;
// import org.apache.commons.codec.binary.Hex;
//
// import javax.crypto.Mac;
// import javax.crypto.spec.SecretKeySpec;
// import java.io.File;
// import java.util.List;
//
// public class SingTest {
//     // public static void main(String[] args) throws Exception {
//     //     String policy_document = "{ \"expiration\": \"2015-12-30T12:00:00.000Z\", \"conditions\": [ {\"bucket\": \"sigv4examplebucket\"}, [\"starts-with\", \"$key\", \"user/user1/\"], {\"acl\": \"public-read\"}, {\"success_action_redirect\": \"http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html\"}, [\"starts-with\", \"$Content-Type\", \"image/\"], {\"x-amz-meta-uuid\": \"14365123651274\"}, {\"x-amz-server-side-encryption\": \"AES256\"}, [\"starts-with\", \"$x-amz-meta-tag\", \"\"], {\"x-amz-credential\": \"AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request\"}, {\"x-amz-algorithm\": \"AWS4-HMAC-SHA256\"}, {\"x-amz-date\": \"20151229T000000Z\" } ]} \n";
//     //
//     //     byte[] utf8_policy = policy_document.getBytes("UTF-8");
//     //
//     //     // Convert the UTF-8-encoded policy bytes to Base64. The result is the StringToSign.
//     //     String base64_policy = new String(Base64.encodeBase64(utf8_policy));
//     //
//     //     // Create a signing key.
//     //     byte[] signing_key = getSignatureKey("UTQGlhB9GJT6ViCTZRhZTT4Sj2kc8iZzfqG8YJlJ" , "20151229", "us-east-2", "s3");
//     //
//     //     // Use the signing key to sign the StringToSign using HMAC-SHA256 signing algorithm.
//     //     byte[] signature_bytes = HmacSHA256(base64_policy, signing_key);
//     //     String signature = Hex.encodeHexString(signature_bytes);
//     //
//     //     System.out.println(base64_policy);
//     //     System.out.println();
//     //     System.out.println(signature);
//     // }
//     //
//     // static byte[] getSignatureKey(String key, String dateStamp, String regionName, String serviceName) throws Exception {
//     //     byte[] kSecret = ("AWS4" + key).getBytes("UTF-8");
//     //     byte[] kDate = HmacSHA256(dateStamp, kSecret);
//     //     byte[] kRegion = HmacSHA256(regionName, kDate);
//     //     byte[] kService = HmacSHA256(serviceName, kRegion);
//     //     byte[] kSigning = HmacSHA256("aws4_request", kService);
//     //     return kSigning;
//     // }
//     //
//     // static byte[] HmacSHA256(String data, byte[] key) throws Exception {
//     //     String algorithm="HmacSHA256";
//     //     Mac mac = Mac.getInstance(algorithm);
//     //     mac.init(new SecretKeySpec(key, algorithm));
//     //     return mac.doFinal(data.getBytes("UTF-8"));
//     // }
//
//     // public static void main(String[] args) {
//     //     AWSCredentials awsCredentials = new BasicAWSCredentials("AKIAXG5FJ3GGXFMAUPAL", "UTQGlhB9GJT6ViCTZRhZTT4Sj2kc8iZzfqG8YJlJ");
//     //     AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
//     //             .withRegion(Regions.US_EAST_2)
//     //             .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
//     //             .build();
//     //
//     //     AccessControlList bucketAcl = s3Client.getBucketAcl("ew10a-prod-upload");
//     //
//     //     List<Grant> grantsAsList = bucketAcl.getGrantsAsList();
//     //     BucketPolicy bucketPolicy = s3Client.getBucketPolicy("ew10a-prod-upload");
//     //     String policyText = bucketPolicy.getPolicyText();
//     //
//     //     // Upload a text string as a new object.
//     //     s3Client.putObject("ew10a-prod-upload", "test", new File("C:\\Users\\Administrator\\Desktop\\干货\\20191021102449938.png"));
//     //
//     //     // Upload a file as a new object with ContentType and title specified.
//     //     PutObjectRequest request = new PutObjectRequest("ew10a-prod-upload", "test", new File("C:\\Users\\Administrator\\Desktop\\干货\\20191021102449938.png"));
//     //     ObjectMetadata metadata = new ObjectMetadata();
//     //     metadata.setContentType("image/jpeg");
//     //     metadata.addUserMetadata("x-amz-meta-title", "someTitle");
//     //     request.setMetadata(metadata);
//     //     s3Client.putObject(request);
//     // }
// }
